/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Helper.AccountHelper;
import common.Constant;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author KIENLT
 */
public class AccountModel extends AbstractTableModel{
    
    ClassLoader cl = this.getClass().getClassLoader();
    
    ArrayList<AccountHelper> AccountList;
    private final String colunmsName[] = { "", Constant.getBundle().getString("id"), Constant.getBundle().getString("nameDoctor"), Constant.getBundle().getString("phone"), Constant.getBundle().getString("email"), Constant.getBundle().getString("levelName") };
    private final Class columnsClass[] = { Boolean.class, String.class, String.class, String.class, String.class, String.class };
    
    public AccountModel(ArrayList<AccountHelper> AccountList){
        this.AccountList = AccountList;
    }
    
    @Override
    public int getRowCount() {
        return AccountList.toArray().length;
    }

    @Override
    public int getColumnCount() {
        return colunmsName.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch(columnIndex){
            case 0 :
                return AccountList.get(rowIndex).isCheck();
            case 1 :
                return AccountList.get(rowIndex).getAccountId();
            case 2 :
                return AccountList.get(rowIndex).getFullName();
            case 3 :
                return AccountList.get(rowIndex).getPhone();
            case 4 :
                return AccountList.get(rowIndex).getEmail();
            case 5 :
                return AccountList.get(rowIndex).getAccountLevelId();
            default : return null;
        }
    }
    
    @Override
    public void setValueAt(Object val, int rowIndex, int columnIndex){
        if(columnIndex==0)
            AccountList.get(rowIndex).setCheck(Boolean.parseBoolean(val.toString()));
        fireTableRowsUpdated(rowIndex, rowIndex);
    }
    
    @Override
    public String getColumnName(int iCol){
        return colunmsName[iCol];
    }
    
    @Override
    public Class getColumnClass(int iCol){
        return columnsClass[iCol];
    }
    
    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex){
        return columnIndex==0;
    }
    
    public void deleteRow(int deleteRow) {
        AccountList.remove(deleteRow);
        AccountList.trimToSize();
        fireTableRowsDeleted(deleteRow, deleteRow);
    }
}
